home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / xgematmath.cc < prev    next >
C/C++ Source or Header  |  1989-08-18  |  1KB  |  74 lines

  1. /*
  2.  *    Math functions for <A>GEMatrix
  3.  *
  4.  *    Copyright (C) 1988, 1989.
  5.  *
  6.  *    Dr. Thomas Keffer
  7.  *    Rogue Wave Associates
  8.  *    P.O. Box 85341
  9.  *    Seattle WA 98145-1341
  10.  *
  11.  *    Permission to use, copy, modify, and distribute this
  12.  *    software and its documentation for any purpose and
  13.  *    without fee is hereby granted, provided that the
  14.  *    above copyright notice appear in all copies and that
  15.  *    both that copyright notice and this permission notice
  16.  *    appear in supporting documentation.
  17.  *    
  18.  *    This software is provided "as is" without any
  19.  *    expressed or implied warranty.
  20.  *
  21.  *
  22.  *    @(#)xgematmath.cc    2.1    8/18/89
  23.  */
  24.  
  25. #include "rw/<A>GEMatrix.h"
  26.  
  27. <A>GEMatrix
  28. transpose(const <A>GEMatrix& m)
  29. {
  30.   register int nr = m.rows();
  31.   register int nc = m.cols();
  32.  
  33.   <A>GEMatrix temp(nc, nr);
  34.  
  35.   for(register int irow=0; irow<nr; irow++)temp.col(irow) = m.row(irow);
  36.  
  37.   return temp;
  38. }
  39.  
  40. // Inner product --- multiply self by m
  41. <A>GEMatrix
  42. <A>GEMatrix::product(const <A>GEMatrix& m)
  43. {
  44.   assertProduct(m);
  45.  
  46.   int nr = rows();
  47.   int nc = m.cols();
  48.  
  49.   <A>GEMatrix temp(nr, nc);
  50.  
  51.   for(int irow=0; irow<nr; irow++){
  52.     <T>Vec arow = row(irow);
  53.     for(int icol=0; icol<nc; icol++)
  54.       temp(irow,icol) = dot(arow, m.col(icol));
  55.   }
  56.  
  57.   return temp;
  58. }
  59.  
  60. <T>Vec
  61. <A>GEMatrix::product(const <T>Vec& v)
  62. {
  63.   assertProduct(v);
  64.  
  65.   int nr = rows();
  66.  
  67.   <T>Vec temp(nr);
  68.  
  69.   for(int irow=0; irow<nr; irow++)
  70.     temp(irow) = dot(row(irow), v);
  71.  
  72.   return temp;
  73. }
  74.